import Vue from 'vue'
import Router from 'vue-router'
import Home from '@/views/Home'
import Login from '@/views/Login'

// import manage from './manage.js'
Vue.use(Router)

import myRouter from "@/router/modules/my.js"
import mallRouter from "@/router/modules/mall.js"
import contactsRouter from "@/router/modules/contacts.js"

export const constantRouterMap = [
    {
        path: '/',
        name: 'home',
        component: Home,
        meta: { title: '聊天' },
        redirect: { name: 'message' },
        children: [{
            path: 'message',
            name: 'message',
            component: () => import('@/pages/message.vue'),
            meta: { title: '聊天' }
        }, {
            path: 'contacts',
            name: 'contacts',
            component: () => import('@/pages/contacts.vue'),
            meta: { title: '通讯录' },
            redirect: { name: contactsRouter[0].name },
            children: contactsRouter
        },
        //  {
        //     path: 'mall',
        //     name: 'mall',
        //     component: () => import('@/pages/mall.vue'),
        //     meta: { title: '商城' }
        // }, 
        {
            path: 'mall',
            name: 'mall',
            component: () => import('@/pages/mall.vue'),
            meta: { title: '商城' },
            redirect: { name: mallRouter[0].name },
            children: mallRouter
        }, {
            path: 'my',
            name: 'my',
            component: () => import('@/pages/my.vue'),
            meta: { title: '我的' },
            redirect: { name: myRouter[0].name },
            children: myRouter
        }]
    },
    {
        path: '/chat',
        name: 'chat',
        component: Home,
        meta: { title: '聊天演示页' }
    },
    {
        path: '/login',
        name: 'login',
        component: Login,
        meta: { title: '登录' }
    },
    {
        path: '/register',
        name: 'register',
        component: () => import('@/views/login/register.vue'),
        meta: { title: '注册' }
    },
    {
        path: '/retrieve',
        name: 'retrieve',
        component: () => import('@/views/login/retrieve.vue'),
        meta: { title: '找回密码' }
    },
    {
        path: '*',
        redirect: '/404',
        hidden: true
    },
    {
        path: '/404',
        component: () => import('@/views/404'),
        hidden: true
    }
];

const createRouter = () => new Router({
    mode: 'hash', // require service support
    scrollBehavior: () => ({ y: 0 }),
    // routes: [...constantRouterMap, ...manage]
    routes: constantRouterMap
})

const router = createRouter()
export function resetRouter() {
    const newRouter = createRouter()
    router.matcher = newRouter.matcher // reset router
}

export default router